<!DOCTYPE html>
<html
        xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/js/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/js/layui/css/public.css" media="all">
    <style>
        .w-e-text-container {
            height: 700px !important; /*!important是重点，因为原div是行内样式设置的高度300px*/
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 0px;">
            <legend>文章添加</legend>
        </fieldset>

        <form class="layui-form layui-form-pane" lay-filter="example" action="" id="form">
            <div class="layui-form-item">
                <div id="editor">
                </div>
            </div>
            <div style="margin: 10px 10px 300px 10px">

                <div class="layui-form-item">
                    <label class="layui-form-label">文章标题:</label>
                    <div class="layui-input-inline">
                        <input type="text" name="articleTitle" autocomplete="off" lay-verify="required"
                               lay-reqtext="请填写文章标题"
                               class="layui-input">
                    </div>
                    <label class="layui-form-label">日期:</label>
                    <div class="layui-input-inline">
                        <input type="text" name="createDate" id="date" autocomplete="off" lay-verify="required"
                               lay-reqtext="前选择创建日期"
                               class="layui-input">
                    </div>
                    <label class="layui-form-label">编辑人:</label>
                    <div class="layui-input-inline">
                        <input type="text" name="createMan" autocomplete="off" lay-verify="required"
                               lay-reqtext="请填写编辑人"
                               class="layui-input">
                    </div>

                    <label class="layui-form-label">文章类型:</label>
                    <div class="layui-input-inline">
                        <select name="articleType" lay-verify="required" lay-reqtext="请选择文章类型">
                            <option value="" selected="">请选择文章类型</option>
                            <option value="常见问题">常见问题</option>
                            <option value="重点提示">重点提示</option>
                            <option value="新闻动态">新闻动态</option>
                            <option value="科研训练">科研训练</option>
                            <option value="成果展示">成果展示</option>
                            <option value="通知公告">通知公告</option>
                        </select>
                    </div>
                </div>

                <input type="hidden" name="articleAttributes" value="1"
                       class="layui-input">


                <div class="layui-form-item">
                    <div class="layui-input-inline">
                        <a class="layui-btn  layui-btn-normal  " lay-submit=""
                           lay-filter="search-btn">修改文章</a>
                    </div>
                </div>
            </div>
            <textarea id="text1" name="articleText" style="display: none;"></textarea>
        </form>
    </div>
</div>
<script src="/static/js/lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="/static/js/layui/layui.js" charset="utf-8"></script>
<script src="/static/js/lib/axios/axios.min.js" charset="utf-8"></script>
<script src="/static/js/lib/edit/wangEditor.js" charset="utf-8"></script>
<script type="text/javascript">
    layui.use(['form', 'table', 'laydate', 'layedit'], function () {
        var $ = layui.jquery,
            form = layui.form,
            layedit = layui.layedit,
            laydate = layui.laydate,
            table = layui.table;

        var parent_json = eval('(' + parent.PartitionJson + ')');
        //注意：parent 是 JS 自带的全局对象，可用于操作父页面
        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引

        console.log(parent_json);

        form.val('example', {
            articleTitle: parent_json.articleTitle,
            articleType: parent_json.articleType,
            createDate: parent_json.createDate,
            createMan: parent_json.createMan,
        })

        editor.txt.html(parent_json.articleText);

        laydate.render({
            elem: '#date'
        });

        form.on('submit(search-btn)', function (data) {
            data = data.field;
            layer.confirm("文章标题：" + data.articleTitle +
                "<br><br>编辑人:" + data.createMan +
                "<br><br>日期:" + data.createDate +
                "<br><br>确定要修改吗？", {
                title: '修改文章'
            }, function (r) {
                if (r) {
                    $.ajax({
                        type: 'put',
                        url: '/article/updateArticle/' + parent_json.id,
                        data: data,
                        dataType: 'json',
                        success: function (data) {
                            if (data.code == 200) {
                                layer.msg("修改文章成功");
                                setTimeout(function () {
                                    reload();
                                }, 1500);
                            } else {
                                layer.alert(data.msg);
                            }
                        }
                    });
                    return false;
                }
            });
            return false;
        });


        function reload() {
            parent.layui.table.reload('articleListTable');//重载父页表格，参数为表格ID
            parent.layer.close(index);
        }

    });
</script>
<script type="text/javascript">
    var E = window.wangEditor
    var editor = new E(document.getElementById('editor'))

    var $text1 = $('#text1')
    editor.customConfig.onchange = function (html) {
        // 监控变化，同步更新到 textarea
        $text1.val(html)
    }
    editor.create()
    // 初始化 textarea 的值
    $text1.val(editor.txt.html())
</script>

</body>
</html>